<?php
if (!defined('ZZQSS')){
	die("Access Denied");
}

/**
 * MailClass 订单操作类
 * add()
 * del()
 * state()
 * getdata()
 *
 */
class MailClass {
	var $db;
	var $table;
	var $tablepre;
	function __construct(){
		//设置全局变量
		global $db,$tablepre;
		$this->db=$db;
		$this->tablepre=$tablepre;
		$this->table=$tablepre."email";
	}
	function MailClass() {
		$this->__construct();
	}
	/**
	 * 添加email入库
	 *
	 * @param string $mailaddress
	 * @param int $uid
	 * @return OK/格式错误
	 */
	function add($mailaddress,$uid=0,$cityid=0){
		global $timestamp;
		if(isemail($mailaddress)){
			$cityid=GetNum($cityid);
			$uid=GetNum($uid);
			if(!$this->db->result_first("select count(*) from {$this->table} where email like '$mailaddress'")){
			$this->db->query("insert into {$this->table}(email,uid,cityid,addtime) VALUES('{$mailaddress}','{$uid}','{$cityid}',$timestamp)");						
				return "OK";
			}return "OK";
		}return "格式错误";
	}
	/**
	 * 删除指定IDemail信息
	 *
	 * @param unknown_type $eid
	 * @return unknown
	 */
	function del($eid){
		if(is_numeric($eid)){
			$this->db->query("delete from {$this->table} where eid='{$eid}'");
			return true;
		}return false;	
	}
	/**
	 * 改变email信息的状态
	 *
	 * @param int $eid
	 * @param 1|0 $state
	 * @return true/false
	 */
	function state($eid,$state=1){
		if(($state==2 || $state==1)&&is_numeric($eid)){
			$this->db->query("update `$this->table` SET state = {$state} WHERE eid={$eid}");
			return true;
		}else return false;	
	}
		/**
	 * 获取数据数组
	 *
	 * @param string $limit
	 * @param string $where
	 * @param string $orderby
	 * @return array
	 */
	function getdata($limit="",$where="",$orderby=""){
		$tempdata=array();
		if(!empty($limit))$limit=" limit $limit ";
		if(!empty($where))$where=" where $where ";
		if(!empty($orderby))$orderby=" order by $orderby ";else $orderby=" order by eid desc";
		$sql="select * from {$this->table}{$where}{$orderby}{$limit}";
		$query =$this->db->query($sql);
		while($value = $this->db->fetch_array($query)) {
			$tempdata[]=$value;
		}
		return $tempdata;
	
	}
	function getcount($where=""){
	if(!empty($where))$where=" where $where";
	$count= $this->db->result_first("Select count(*) From `$this->table` $where");
	return $count;
	
	}
}
?>